<script lang="ts">
import md5Libs from "uview-ui/libs/function/md5";

// #ifdef APP-PLUS || H5
import { TUIChatKit } from "./TUIKit";
import { vueVersion } from "./TUIKit/adapter-vue";
// import { TUILogin } from "@tencentcloud/tui-core";, genTestUserSig
// #endif
// 必填信息
const config = {
  userID: "lizhi", // User ID
  SDKAppID: '1600039658', // Your SDKAppID
  secretKey: "4219ef1d4ca7124717057aa5570b0cab822f8edd7f12373218ed31fa4ec8502d", // Your secretKey
};
uni.$chat_SDKAppID = config.SDKAppID;
uni.$chat_secretKey = config.secretKey;
uni.$vueVersion = `vue${vueVersion}`

// #ifdef APP-PLUS || H5
// UserSig 是用户登录即时通信 IM 的密码，其本质是对 UserID 等信息加密后得到的密文。
// 该方法仅适合本地跑通 Demo 和功能调试，详情请参见 https://cloud.tencent.com/document/product/269/32688 
// uni.$chat_userSig = genTestUserSig(config).userSig;
// TUIChatKit 初始化
TUIChatKit.init();
// #endif


export default {
	onLaunch: async function() {
    console.log('11eeee')
		console.log('uview 版本', this.$u.config.v);
    console.log('uni ==wwwwwwwww----------------w=', uni.getStorageSync('username'))
    uni.setStorageSync('token',this.vuex_token)
    
    // #ifdef APP-PLUS || H5
    if(this.vuex_user && uni.getStorageSync('username')){
      this.$api.talkLogin(uni.getStorageSync('username'))
    }
    
    // #endif

    
		// #ifdef H5
		if(window.location.hash != ''){
			 let search = window.location.search.substring(1);
			    try{
			        if(search.indexOf('hashpath') != -1){
			            let sea = JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}');
			            if(sea.hashpath && sea.code && sea.state){
			                window.location.href = window.location.origin + window.location.pathname+'#'+sea.hashpath+'?code='+sea.code+'&state='+sea.state
			            }
			        }
			    }catch(e){
			        //TODO handle the exception
			    }
		}
		// #endif

		//加载配置
		let res = await this.$api.getConfig();
		if (!res.code) {
			return;
		}
		//主题做缓存
		let theme_key = md5Libs.md5(JSON.stringify(res.data.theme));
		if(!this.vuex_theme.key || this.vuex_theme.key != theme_key){
			this.$u.vuex('vuex_theme', {key:theme_key,value:res.data.theme});
		}
		
		this.$u.vuex('vuex_config', res.data);
		
		// #ifdef APP-PLUS
		let tabbar = this.$u.deepClone(this.vuex_config.tabbar);
		if (!tabbar) {
			this.$util.setTabbar(this.vuex_tabbar);
			return;
		}
		let num = 0;
		for (let i in tabbar.list) {
			try {
				let imagepath = await this.$util.getCachedImage(tabbar.list[i].image);
				let selectedImage = await this.$util.getCachedImage(tabbar.list[i].selectedImage);
				tabbar.list[i].image = imagepath;
				tabbar.list[i].selectedImage = selectedImage;
				num = i;
			} catch (e) {
				console.log(e);
			}
		}
		//更新tabbar配置
		this.$u.vuex('vuex_config.tabbar.list', tabbar.list);
		return ;
		
		//全部下载成功使用服务器的导航，否则启用本地备用导航
		if (parseInt(num) + 1 == tabbar.list.length) {
			this.$util.setTabbar(tabbar);
		} else {
			this.$util.setTabbar(this.vuex_tabbar);
		}
		// #endif
	},
	onShow: function() {
		console.log('App Show');
	},
	onHide: function() {
		console.log('App Hide');
	}
};
</script>

<style lang="scss">
@import 'uview-ui/index.scss';
.tui-contact-list-card-left,.tui-contact-list-card-left-avatar{width:80rpx !important; height:80rpx !important}
.tui-search-input-container .tui-search-input{background-color: #F5F7FB !important; margin: 20rpx 16rpx 20rpx 30rpx !important;}
.uni-page-head{
  background-color: #fff !important;
  .uni-page-head__title{color: #333 !important;}
  .uni-btn-icon{color: #333 !important;}
}
.tui-conversation-item .left,.tui-conversation-item .left .avatar-container{width: 80rpx !important; height: 80rpx !important;}
.tui-conversation-item .content{padding-left: 20rpx !important;}
page, uni-page-body {
  width: 100vw !important;
  height: 100vh !important;
  overflow: auto; background-color: #fff !important;
}
.tui-conversation-item .content-header .middle-box{margin-top: 12rpx !important;}
.tui-search-input-container-h5 .tui-search-input-h5{height: 76rpx !important;}
.tui-search-more-h5 .more{background-color: #F5F7FB !important; border-radius: 6rpx; margin-right: 30rpx !important; display: flex; align-items: center; justify-content: center;}

.search-more .common-icon-container-mobile .common-icon{width: 50rpx !important; height: 50rpx !important;}
.tui-conversation-item{padding: 22rpx 16rpx !important; margin: 0 18rpx !important; border-radius: 8rpx;}
// .tui-conversation-item .left{margin-left: 12rpx;}
// .tui-conversation-item .content{margin-right: 12rpx;}
.tui-conversation-item:hover{background-color: #EBECED;}
/*每个页面公共css */
.u-bg-white {
	background-color: #ffffff;
}
.u-text-weight {
	font-weight: bold;
}
.login {
  .text{height: 120rpx;}
  .u-form-item{border-bottom: 1px solid #E4E4E4; padding: 0px 0 !important; position: relative;}
  .u-form-item__message{position: absolute; bottom: 3rpx; left: 0;}
  .zxb-btn{height: 96rpx; width: 100%; display: flex; align-items: center; justify-content: center; background-color: #151515; color: #fff; border-radius: 50rpx; margin-bottom: 40rpx; font-size: 32rpx;
    &.btn1{margin-top: 100rpx;}
  }
  .ice{position: absolute; right: 0; top: 50%; transform: translateY(-50%); width: 50rpx; height: 50rpx; z-index: 89;}
  .text .u-input__input{height: 120rpx;  font-size: 30rpx;} 
  .text2 .u-input__input,.u-form-item--left__content__label{font-size: 30rpx;} 
  .radio{
    .u-checkbox__icon-wrap{border-radius: 50%;}
  }
}
.addedit{
  .u-form-item{padding: 0 32rpx !important;}
}
.u-line-height {
	line-height: 50rpx;
}

.bg-white {
	background-color: #ffffff;
}
.price {
	color: $u-type-error;
}
.text-weight {
	font-weight: bold;
}
.text-normal {
	font-weight: normal;
}

.fa-empty {
	width: 100%;
	flex-direction: column;
	image {
		width: 400rpx;
		height: 400rpx;
	}
	&.top-15 {
		padding-top: 15vh;
	}
}
.footer-bar {
	position: fixed;
	left: 0;
	bottom: 0;
	width: 100%;
	height: 120rpx;
	background-color: #ffffff;
	padding: 0 30rpx;
	z-index: 9999;
}

.share-btn {
	padding: 0;
	margin: 0;
	border: 0;
	background-color: transparent;
	line-height: inherit;
	border-radius: 0;
	font-size: inherit;
	color: #999;
}
.share-btn::after {
	border: none;
}

// #ifdef MP-BAIDU
.u-radio__icon-wrap,.u-checkbox__icon-wrap{
	line-height: 0;
}
// #endif
.u-load-more-wrap{
  background-color: transparent !important;
  .u-more-text{background-color: transparent !important;}
}
</style>
